using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class PageIndicator : MonoBehaviour
{
    [SerializeField] Text text;
    [SerializeField] CanvasGroup canvasGroup;
    public static int lastIndex;
    private int curIndex, maxIndex;
    private bool isVisible = false;
    float visibleTime = 0f;
    // Start is called before the first frame update
    void Start()
    {
        text.text = curIndex.ToString() + " / " + maxIndex.ToString();
    }

    // Update is called once per frame
    void Update()
    {
        text.text = curIndex.ToString() + " / " + maxIndex.ToString();
        if (curIndex != lastIndex) { isVisible = true; visibleTime = 0f; }
        if (isVisible)
        {
            visibleTime += Time.deltaTime;
            if (canvasGroup.alpha < 1)
            {
                canvasGroup.alpha += 5 * Time.deltaTime;
            }
            else if (visibleTime > 2f) isVisible = false;
        }
        else if (canvasGroup.alpha > 0)
        {
            canvasGroup.alpha -= 3 * Time.deltaTime;
        }
        lastIndex = curIndex;
    }
}
